Glasgow Class 6 Melese Berehannu JavaScript-Core-2-Coursework-Week1#218
Glasgow Class 6 Melese Berehannu JavaScript-Core-2-Coursework-Week1#218Melesegithub wants to merge 1 commit into
Conversation
annacollins85
left a comment
There was a problem hiding this comment.
Great work again 🙌 Just a few comments but you've done a really good job. Well done!
| */ | ||
|
|
||
| // write code here | ||
| const topPlayers = (basketballTeam.topPlayers).sort() |
There was a problem hiding this comment.
This works here since all the strings use upper case for the first letter. Be careful with using sort for strings without passing a custom function. This is because all uppercase letters are "smaller" than lower case ones. So "M" for example would be sorted before "a". Here is an article explaining in more detail and how to handle it if you want to make your sort case insensitive https://www.danywalls.com/understand-how-the-sort-method-operates-on-javascript-arrays
| }, | ||
| }; | ||
|
|
||
| //we should log myPet.getName only () not required |
There was a problem hiding this comment.
This is not the case. getName is indeed a function, so we need to use () to call it. The problem here is that the get name function is not returning anything, so it returns undefined. It should be:
getName: function() {
return "My pet's name is Fluffy";
}| getName: function getName(name){ | ||
| return name | ||
| } |
| } | ||
|
|
||
| student.getName("Daniel"); | ||
| let studentName = student.getName("Daniel"); |
There was a problem hiding this comment.
It doesn't affect the code working, but we should only use let to define a variable if we are going to change it later on. In other cases, we should use const. This makes our code "safer" as we will only be able to reassign variables that we define as let, and expect to be changed. (Note: there are other subtle differences with let/const related to scope, but I wouldn't advise worrying about it at this stage).
| Ingredients: ['Macharpnni', 'Cheese', 'Salt'] | ||
| }} | ||
| for (item of favouriteRecipe){ | ||
| console.log(item.) |
There was a problem hiding this comment.
This exercise has made me hungry 😂
| @@ -18,7 +18,17 @@ const COUNTRY_CURRENCY_CODES = [ | |||
| ]; | |||
|
|
|||
| function createLookup(countryCurrencyCodes) { | |||
| newObject[country] = countryCode; | ||
|
|
||
|
|
||
| }return newObject; |
There was a problem hiding this comment.
Be careful with formatting here. The indentation on line 23 and this return statement should be on a new line.
| let countryCode = countryCurrencyCode[1]; | ||
| let country = countryCurrencyCode[0]; |
There was a problem hiding this comment.
Again, here we can use const. It may seem that we are reassigning these variables as we loop through the array, but we aren't, we are creating new ones on each iteration. This means they are never reassigned and disappear after each loop iteration.
| @@ -20,6 +20,24 @@ let pantry = { | |||
|
|
|||
| function createShoppingList(recipe) { | |||
There was a problem hiding this comment.
Nice! Another way of doing this would be to use filter:
const missingIngredients = recipe.ingredients.filter(function (item) {
!pantryContents.includes(ingredients)
}| @@ -21,8 +21,28 @@ const MENU = { | |||
|
|
|||
| let cashRegister = { | |||
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?